<template>
	<view class="page">
		
		<scroll-view scroll-y="true" style="height: 100%;">
		
		<navigator url="editHeadPic/editHeadPic" class="headPic input-block list-item">
			<view class="left">
				<label>头像</label>
			</view>
			<view class="center">
				
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</navigator>
		
		<navigator url="../doing/doing" class="sign navigation-block list-item">
			<view class="left">
				<label>签名</label>
			</view>
			<view class="center omit">
				<text>{{user.personalSignature}}</text>
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</navigator>
		
		<view class="nickName input-blcok list-item" style="margin-top: 30rpx;">
			<view class="left">
				<label>昵称</label>
			</view>
			<view class="center">
				<input type="text" value="" v-model="user.nickName" 
				@confirm="updataUserInfo(user)"
				@blur="updataUserInfo(user)" />
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</view>
		
		<view class="sex picker-block list-item">
			<view class="left">
				<label>性别</label>
			</view>
			<view class="center">
				<picker @change="sexPickerChange" :value="sexIndex" :range="sexList" range-key="name">
					<view class="uni-input">{{sexList[sexIndex].name}}</view>
				</picker>
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</view>
		
		<view class="birthday picker-block list-item">
			<view class="left">
				<label>生日</label>
			</view>
			<view class="center">
				 <picker mode="date" :value="user.birthday" :start="startDate" :end="endDate" @change="bindDateChange">
					 <view class="uni-input">{{user.birthday ? getFormateDate(new Date(user.birthday)) : ''}}</view>
				 </picker>
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</view>
		<view class="" style="height: 60rpx;line-height: 60rpx; margin-left: 30rpx;">
			<text>教育经历</text>
		</view>
		<navigator url="../doing/doing" class="university click-block list-item">
			<view class="left">
				<navigator url="../doing/doing">添加大学</navigator>
			</view>
			<view class="center">
			</view>
			<view class="right">
			</view>
		</navigator>
		<navigator url="../doing/doing" class="middle-school click-block list-item">
			<view class="left">
				<navigator url="../doing/doing">添加中学</navigator>
			</view>
			<view class="center">
			</view>
			<view class="right">
			</view>
		</navigator>
		<navigator url="../doing/doing" class="prime-school click-block list-item">
			<view class="left">
				<navigator url="../doing/doing">添加小学</navigator>
			</view>
			<view class="center">
			</view>
			<view class="right">
			</view>
		</navigator>
		
		<view class="profession input-blcok list-item" style="margin-top: 30rpx;">
			<view class="left">
				<text>职业</text>
			</view>
			<view class="center">
				<input type="text" value="" v-model="user.profession"
				@confirm="updataUserInfo(user)"
				@blur="updataUserInfo(user)" />
			</view>
			<view class="right">
			</view>
		</view>
		
		<view class="company input-blcok list-item">
			<view class="left">
				<text>公司</text>
			</view>
			<view class="center">
				<input type="text" value="" v-model="user.company" 
				@confirm="updataUserInfo(user)"
				@blur="updataUserInfo(user)" />
			</view>
			<view class="right">
			</view>
		</view>
		
		<navigator url="../doing/doing" class="address navigation-block list-item">
			<view class="left">
				<text>所在地</text>
			</view>
			<view class="center">
				{{user.address}}
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</navigator>
		
		<navigator url="../doing/doing" class="hometown navigation-block list-item">
			<view class="left">
				<text>家乡</text>
			</view>
			<view class="center">
				{{user.address}}
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</navigator>
		
		<view class="email input-block list-item">
			<view class="left">
				<text>邮箱</text>
			</view>
			<view class="center">
				<input type="text" value="" v-model="user.email" 
				@confirm="updataUserInfo(user)"
				@blur="updataUserInfo(user)" />
			</view>
			<view class="right">
			</view>
		</view>
		
		<navigator url="../doing/doing" class="introduction navigation-block list-item" style="margin: 20rpx 0;">
			<view class="left">
				<text>个人说明</text>
			</view>
			<view class="center">
				<input type="text" value="" placeholder="介绍一下自己吧" v-model="user.introduction" />
			</view>
			<view class="right">
				<label class="iconfont icon113fangxiang_xiangyou"></label>
			</view>
		</navigator>
		
		</scroll-view>
	</view>
</template>

<script>
	
	var _self
	import utils from '@/common/util.js'
	
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				user: {},
				sexIndex: 0,
				oldSexIndex: 0,
				date: currentDate,
				sexList: [
					{
						name: "男",
						value: "man"
					},
					{
						name: "女",
						value: "woman"
					}
				]
			}
		},
		onLoad() {
			_self = this
			var userinfo = uni.getStorageSync("userInfo")
			if(userinfo != ""){
				_self.user = userinfo
				if(userinfo.sex == 'man'){
					this.sexIndex = this.oldSexIndex =0
				}else{
					this.sexIndex = this.oldSexIndex =1
				} 
			}else{
				// 关闭所有页面跳转登录页面 同时关闭定时任务
				uni.reLaunch({
					url:'../../login/addAndRegister/addAndRegister',
					animationType: 'pop-in',
					animationDuration: 200
				})
			}
			
				
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			sexPickerChange(event){
				this.oldSexIndex = this.sexIndex
				this.sexIndex = event.detail.value
				this.user.sex = this.sexList[event.detail.value].value
				utils.updataUserInfo(_self.user)
			},
			bindDateChange: function(e) {
				this.date = e.target.value
				this.user.birthday = this.date
				utils.updataUserInfo(_self.user)
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
	
				if (type === 'start') {
					year = year - 120;
				} else if (type === 'end') {
					year = year ;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			getFormateDate(date) {
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
		}
	}
</script>

<style>
	@import url("editUserInfo.css");
</style>
